package Q2;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] arr = new int[n][m];

        long[] rowSum = new long[n]; //每一行的和
        long[] colSum = new long[m]; //每一列的和

        for (int i = 0; i < n; i++) {
            long sum = 0;
            for (int j = 0; j < m; j++) {
                arr[i][j] = scanner.nextInt();
                sum += arr[i][j];
            }
            rowSum[i] = sum;
        }

        for (int j = 0; j < m; j++) {
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += arr[i][j];
            }
            colSum[j] = sum;
        }

        long[][] ret = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ret[i][j] = rowSum[i] + colSum[j] - arr[i][j];
                System.out.print(ret[i][j] + " ");
            }
            System.out.println();
        }

    }
}
